﻿<?php
/*
 * Created on Feb 19, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class ItemModel {
	
	function ItemModel() {	
	}
		
	function getItemByTransactionId($id = null, $offset = null, $limit = null) {
		global $connDB;  //The database connection
		if ($id == null) return null;
		
		$sql = 	"SELECT item.id,".
					" item.rees_type_id,".
					" item.rees_cityregion_id,".
					" item.rees_transaction_id,".
					" item.rees_district_id,".
					" item.rees_user_id,".
					" item.title,".
					" item.description,".
					" item.content,".
					" item.contact,".
					" item.place,".
					" item.source,".
					" item.direction,".
					" item.size,".
					" item.price,".
					" item.image,".
					" item.isSpecial,".
					" item.endDate,".
					" item.activeFlag,".
					" item.createDate,".
					
					" dist.name distric_name,".
					" city.name city_name".
				" FROM ".TBL_ITEM. " item".
				" INNER JOIN ".TBL_DISTRICT." dist ON dist.id = item.rees_district_id".
				" INNER JOIN ".TBL_CITY." city ON city.id = dist.rees_city_id".
				" WHERE item.rees_transaction_id = ".$id.
				" ORDER BY item.createDate DESC ".getLimitFormat($offset, $limit);  
		 		
		$result = $connDB->DB_query($sql, $connDB->connection);
		
		return $result;
	}
	
	function getItemByTypeId($typeId = null, $offset = null, $limit = null) {
		global $connDB;   
		if ($typeId == null) {
			
			return null;
		}
		$sql = 	"SELECT item.id,".
					" item.rees_type_id,".
					" item.rees_cityregion_id,".
					" item.rees_transaction_id,".
					" item.rees_district_id,".
					" item.rees_user_id,".
					" item.title,".
					" item.description,".
					" item.content,".
					" item.contact,".
					" item.place,".
					" item.source,".
					" item.direction,".
					" item.size,".
					" item.price,".
					" item.image,".
					" item.isSpecial,".
					" item.endDate,".
					" item.activeFlag,".
					" item.createDate".
				" FROM ".TBL_ITEM. " item".
				" WHERE item.rees_type_id = ".$typeId.
				" ORDER BY item.createDate DESC ".getLimitFormat($offset, $limit);   
		 		
		$result = $connDB->DB_query($sql, $connDB->connection);
		
		return $result;
	}
	
	function getItemTitleById($id = null) {
		global $connDB;   
		if ($id == null) return null;
		$sql = 	"SELECT  item.title FROM ".TBL_ITEM. " item".
				" WHERE item.id = ".$id;
		$result = $connDB->DB_query($sql, $connDB->connection);		
		return $connDB->DB_fetch_array($result);
	}
	
	function getTypeName($typeId = null) {
		global $connDB;   
		if ($typeId == null) {
			
			return null;
		}
		$sql = 	"SELECT type.name".
				" FROM ".TBL_REALESTATE_TYPE. " type".
				" WHERE type.id = ".$typeId.
				" LIMIT 1 ";   
		$result = $connDB->DB_query($sql, $connDB->connection);
		
		return $connDB->DB_fetch_array($result);
	}
	
	function countItemByTypeId($typeId = null) {
		global $connDB;  
		if ($typeId == null) {
			
			return null;
		}
		$sql = 	"SELECT * FROM ".TBL_ITEM. " item".
				" WHERE item.rees_type_id = ".$typeId."";  
		$result = $connDB->DB_query($sql, $connDB->connection);
		
		return $connDB->DB_num_rows($result);
	}
	
	function countItemByTransactionId($id = null) {
		global $connDB;  //The database connection
		if ($id == null) return null;
		
		$sql = 	"SELECT * FROM ".TBL_ITEM. " item".
				" WHERE item.rees_transaction_id = ".$id.""; 
		$result = $connDB->DB_query($sql, $connDB->connection);
		
		return $connDB->DB_num_rows($result);
	}
	
	function getArrayNameInfos($resultSet = null){
		global $connDB;  //The database connection
		if($resultSet == null) return null;
		return $connDB->DB_fetch_array($resultSet);
	}
};

/* Create cityregion controller object */
$itemModel = new ItemModel;
?>